from PIL import Image, ImageEnhance
import pytesseract
def recognize_captcha(img_path):
    image=Image.open(img_path)
    image=image.convert('L')            #转换模式：L|RGB
    image=ImageEnhance.Contrast(image)  #增强对比度
    image=image.enhance(2.0)            #增强饱和度
    image.save(img_path)
    image = Image.open(img_path)
    num=pytesseract.image_to_string(image)
    return num

if __name__=='__main__':
    img_path='../images/code.png'
    num=recognize_captcha(img_path)
    print(num)